﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BestLifePOS_Core.Data.Core;
using System.Data;
using System.Data.SqlClient;
using BestLifePOS_Core.Exceptions.DataBase;

namespace BestLifePOS_Core.Data.Fascade
{

    class BestlifeGetStockByProId : BestLifeDataAction<DataTable>
    {
        private string PProId;
        DataTable ProTable = new DataTable();

        public BestlifeGetStockByProId(string PProId)
        {
           this.PProId = PProId;

        }


        public override DataTable Body(SqlConnection PConn)
        {
            try
            {

                #region Datatable

                ProTable.Columns.Add("Stock_Id");
                ProTable.Columns.Add("Pro_Name");
                ProTable.Columns.Add("Category");
                ProTable.Columns.Add("Qty");
                ProTable.Columns.Add("Reorder_Qty");
                ProTable.Columns.Add("Reorder_Level");



                #endregion

                List<string> LvList = new List<string>();


                SqlCommand LvCommand = new SqlCommand();
                LvCommand.Connection = PConn;
                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.Parameters.Add(new SqlParameter("@Pro_Id", PProId));//when passing parameters to the SP
                LvCommand.CommandText = "dbo.GetStockByProId";



                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    ProTable.Rows.Add(ProTable.NewRow());
                    //    string GVTest;

                    ProTable.Rows[ProTable.Rows.Count - 1][0] = LvReader.GetValue(0).ToString();
                    ProTable.Rows[ProTable.Rows.Count - 1][1] = LvReader.GetValue(1).ToString();
                    ProTable.Rows[ProTable.Rows.Count - 1][2] = LvReader.GetValue(2).ToString();
                    ProTable.Rows[ProTable.Rows.Count - 1][3] = LvReader.GetValue(3).ToString();
                    ProTable.Rows[ProTable.Rows.Count - 1][4] = LvReader.GetValue(4).ToString();
                    ProTable.Rows[ProTable.Rows.Count - 1][5] = LvReader.GetValue(5).ToString();

                    //    GVTest.
                    //GvTable.Rows[GvTable.Rows.Count - 1][7] = "0";



                }
                return ProTable;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }

    }
}
